//
//  ViewController.m
//  11102
//
//  Created by student on 16/3/6.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;
- (IBAction)btnPressed:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    for (int i=0; i<6; i++) {
        UIImage *image=[UIImage imageNamed:[NSString stringWithFormat:@"%i",i+1]];
        UIImageView *imageView=[[UIImageView alloc]initWithImage:image];
        imageView.frame=CGRectMake(320*i, 0, 320, 200);
        self.scrollView.contentSize=CGSizeMake(320*6, 200);
        [self.scrollView addSubview:imageView];
    }
    self.scrollView.pagingEnabled=YES;
    self.scrollView.showsVerticalScrollIndicator=NO;
    
    self.pageControl.currentPage=0;
    self.pageControl.numberOfPages=6;
    self.pageControl.pageIndicatorTintColor=[UIColor blueColor];
    self.pageControl.currentPageIndicatorTintColor=[UIColor redColor];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.pageControl.currentPage=self.scrollView.contentOffset.x/320;
}

- (IBAction)btnPressed:(id)sender {
    UIButton *btn=sender;
    self.scrollView.contentOffset=CGPointMake((btn.tag-101)*320, 0);
}
@end
